/*
 * 4.2.cpp
 *
 *  Created on: 2012-5-17
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

#define LEN 1001

int main (void) {
	int n;
	cin >> n;
	while (n--) {
		int characters[26]={0};
		char str[LEN];
		cin >> str;
		for (int i=0; i<strlen(str); i++) {
			characters[str[i]-'a']++;
		}
		int k = characters[0];
		for (int i=1; i<26; i++) {
			if(characters[i] > k) k =i;
		}
		printf("%c %d", k+'a', characters[k]);
	}
	return 0;
}
